#include "led.h"
#include "delay.h"
#include "key.h"
#include "sys.h"
#include "lcd.h"
#include "usart.h"
#include "can.h"
#include "encoder.h"
#include "usart3.h"
#include "spi.h"
#include "lsm6dsl.h"
#include "SpiPeripheral.h"
#include "ImuSensor.h"
#include "encoder.h"
#include "timer.h"
#include "fault_code.h"
#include "OpenImu.h"
#include "WingbowHost.h"
//#include "stm32f10x_rcc.h"
//#include "IMU_ADIS16505.h"

OpenImu *openImu;
WingbowHost *wingbowHost;

// RCC_ClocksTypeDef RCC_Clocks;

int main(void)
{

    // RCC_GetClocksFreq(& RCC_Clocks); //拿到系统时钟频率
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //设置中断优先级分组为组2：2位抢占优先级，2位响应优先级
    delay_init();                                   //延时函数初始化
    uart_init(115200);                              //串口1初始化为115200
    usart3_init(115200);                            //串口3初始化为115200
    uart4_init(115200);                             //串口4初始化为115200

    LED_Init();                                                               //初始化与LED连接的硬件接口
    KEY_Init();                                                               //按键初始化
    CAN_Mode_Init(CAN_SJW_1tq, CAN_BS2_8tq, CAN_BS1_9tq, 4, CAN_Mode_Normal); //CAN初始化环回模式,波特率500Kbps
    EncoderInit();  
    wingbowHost = WingbowHost::get();
    wingbowHost->init();
    openImu = OpenImu::get();
    openImu->init();
    TIM3_Int_Init(199,7199);            //20ms定时器

    // Encoder_Demarcate_Zero()  ;      //编码器标定，出厂时使用
    while (1)
    {

        mainloop();
        //loop20ms();
        loop200ms();
    }
}
